define(function(require, exports, module) {
    var zlib = require('zlib');
    var pCommon = require('common');
    var demo = {};

    demo.init = function(){
        tmplInit();
        openDivInit();

        pCommon.tabs.init("#tabChange", {ev:"mouseover", tabOnClass:"tab_on"});
        //复写全局默认参数
        //pCommon.slider.opts.time = 3000;
        pCommon.slider.init("#slidBanner1", {type: "v"});
        pCommon.slider.init("#slidBanner2", {type: "h"});
        pCommon.slider.init("#slidBanner3", {type: "a"});
        pCommon.slider.init("#slidBanner4", {type: "n"});

        pCommon.floatDiv.init("#floatDiv", {"type":2});
        pCommon.back2top("#back2top", {"posY":20});
    };


    //前端模版初始化
    function tmplInit() {
        var dataObject = {
            id: 101,
            profile_image_url: 'http://www.baidu.com/img/bdlogo.gif',
            from_user: "zc",
            text: "hahahahaah"
        }
        var results = document.getElementById("results");
        var html = "";
        html  = zlib.tmpl("item_tmpl", dataObject);
        results.innerHTML = html;


        var userObj =
        {
            users:[
                    {
                        url: "www.user.com",
                        name: "zc"
                    },
                    {
                        url: "www.user2.com",
                        name: "zc2"
                    },
                    {
                        url: "www.user2.com",
                        name: "zc3"
                    }
                ]
        };
        var results2 = document.getElementById("results2");
        var html2 = "";
        html2  = zlib.tmpl("user_tmpl", userObj);
        results2.innerHTML = html2;
    }

    //弹出层
    function openDivInit() {
        require.async('./layer/layer', function(){
            var iframeDiv, pageDiv, alertDiv, confirmDiv, tipsDiv, msgDiv;
            $("#iframeDiv").click(function(){
                pageDiv = $.layer({
                    title: "iframeDiv",
                    type : 2,
                    area : ['500px', '500px'],
                    closeBtn : [0, true],
                    iframe: {
                        src: 'http://sentsin.com'
                    }
                });

            });

            $("#pageDiv").click(function(){
                pageDiv = $.layer({
                    title: "登录",
                    type : 1,
                    area : ['500px', 'auto'],
                    move : false,
                    closeBtn : [1, true],
                    page : {dom : '#results'}
                });

            });

            $("#alertDiv").click(function(){
                alertDiv = layer.alert("内容", 0, "标题", function(){
                    alert("回调");
                });
            });

            $("#confirmDiv").click(function(){
                confirmDiv = layer.confirm("内容", function(){
                    alert("回调1,关闭tipsDiv");
                    //关闭tipsDiv
                    layer.close(tipsDiv);
                }, "标题", function(){
                    alert("回调2");
                });
            });

            $("#msgDiv").click(function(){
                msgDiv = layer.msg("内容",2, 1, function(){
                    alert("msgDiv索引值：" + msgDiv);
                });
            });

            $("#tipsDiv").click(function(){
                tipsDiv = layer.tips("这是小提示", this);
            });
        });
    }

    // 暴露对应接口
    module.exports = demo;

});


